package com.lovo.Atm;

import com.lovo.Util;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Find extends JPanel implements ActionListener {
    private JButton backImg;
    private JLabel findText = new JLabel("余额：");
    private JLabel blanceText;
    private Home frame;
    private Icon backBtn = Util.iconImg("/images/buttonOff.jpg");

    public Find(Home frame) {
        this.frame = frame;
        this.setLayout(null);
        this.setOpaque(false);

        //余额提示
        findText.setBounds(420, 240, 70, 30);
        findText.setFont(new Font("宋体", Font.BOLD, 20));
        this.add(findText);

        //查询金额显示
        blanceText = new JLabel();
        blanceText.setBounds(500, 240, 100, 30);
        blanceText.setFont(new Font("宋体", Font.BOLD, 20));
        this.add(blanceText);

        //返回按钮，菜单界面
        backImg = new JButton(backBtn);
        backImg.setBounds(650, 300, 140, 50);
        this.add(backImg);
        backImg.addActionListener(this);

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (backImg == e.getSource()) {
            frame.switchPanel("menu");
        }
    }
    //需要传入一个double类型的参数，才能将该用户的当前余额传进函数
    public void set(double blance) {
        // 显示出的是String，需要双引号转为字符串
        frame.getLoginUser().setBlance(blance);
        blanceText.setText(blance + "");
    }

}
